<template>
  <div class="container">
    <div style="padding: 0px 20px">
      <VolHeader
        icon="md-apps"
        text="控烟调查明细"
        style="margin-bottom: 10px; border: 0px; margin-top: 15px"
      >
        <div slot="content">本次控烟调查上传图片打包<a target='_blank' href='http://localhost:3000/images/zip/kongyan.aipack.zip' >下载</a>(由于系统处理延迟等原因，请在检查完成第二天下载完整图片包)</div>
        <slot>
          <div style="text-align: right">
            <Select
              clearable
              v-model="searchdata"
              :placeholder="'请选择' + searchOptions.title"
              style="width: 130px"
            >
              <Option
                v-for="(kv, kvIndex) in searchOptions.data"
                :key="kvIndex"
                :value="kv.key || ''"
                >{{ kv.value }}</Option
              >
            </Select>
            <Button type="info" ghost @click="load" style="margin-left: 20px">查询</Button>
            <Button type="info" ghost @click="exp">导出</Button>
          </div>
        </slot>
      </VolHeader>
      <div>
        <div class="order-title" v-if="searchdata!='2'">
          <h2>党政机关</h2>
        </div>
        <div data-v-542f4644 class="ivu-row" style="padding: 15px; background: white" v-if="searchdata!='2'">
          <table id="table" cellspacing="0">
            <caption></caption>
            <tr>
              <th scope="col" style="width:50px;" rowspan="2">序号</th>
              <th scope="col" style="width:70px;" rowspan="2">组别</th>
              <th scope="col" rowspan="2">机关名称</th>
              <th scope="col" rowspan="2">基准分</th>
              <th scope="col" rowspan="2">1.各入口是否有明显禁烟提示</th>
              <th scope="col" colspan="5">2.室内场所情况</th>
              <th scope="col" rowspan="2">3.是否设置室外吸烟区</th>
              <th scope="col" rowspan="2">4.无烟党政机关承诺</th>
              <th scope="col" rowspan="2">5.控烟宣传形式</th>
              <th scope="col" rowspan="2">6.是否出售烟草制品</th>
              <th scope="col" rowspan="2">7.是否有烟草广告、促销或赞助</th>
              <th scope="col" rowspan="2">小计</th>
              <th scope="col" rowspan="2">备注</th>
            </tr>
            <tr>
              <th scope="col">(1)禁烟标识</th>
              <th scope="col">(2)有烟味</th>
              <th scope="col">(3)有人吸烟</th>
              <th scope="col">(4)有烟具</th>
              <th scope="col">(5)有烟头</th>
            </tr>
            <tr v-for="(item, key) in officedetails" :key="key">
              <th abbr="Model" class="spec">{{key+1}}</th>
              <th abbr="Model" class="spec">{{item.groupname}}</th>
              <th abbr="Model" class="spec">{{item.unitname}}</th>
              <td>75</td>
              <td>{{item.answer[0]}}</td>
              <td>{{item.answer[1]}}</td>
              <td>{{item.answer[2]}}</td>
              <td>{{item.answer[3]}}</td>
              <td>{{item.answer[4]}}</td>
              <td>{{item.answer[5]}}</td>
              <td>{{item.answer[6]}}</td>
              <td>{{item.answer[7]}}</td>
              <td>{{item.answer[8]}}</td>
              <td>{{item.answer[9]}}</td>
              <td>{{item.answer[10]}}</td>
              <td>{{item.total}}</td>
              <td>{{item.remark}}</td>
            </tr>
          </table>
        </div>

        <div class="order-title" v-if="searchdata!='2'">
          <h2>党政机关场所明细</h2>
        </div>
        <div data-v-542f4644 class="ivu-row" style="padding: 15px; background: white" v-if="searchdata!='2'">
          <table id="tabledetail" cellspacing="0">
            <caption></caption>
            <tr>
              <th scope="col" style="width:50px;">序号</th>
              <th scope="col" style="width:70px;">组别</th>
              <th scope="col">机关名称</th>
              <th scope="col">控烟项目</th>
              <th scope="col">1.食堂</th>
              <th scope="col">2.一楼大厅</th>
              <th scope="col">3.电梯</th>
              <th scope="col">4.会议室</th>
              <th scope="col">5.办公室</th>
              <th scope="col">6.男厕所</th>
              <th scope="col">7.走廊</th>
              <th scope="col">8.楼梯</th>
              <th scope="col">9.传达室(门卫)</th>
              <th scope="col">10.其他</th>
            </tr>
            <tr v-for="(item, key) in officeplacedetails" :key="key">
              <th abbr="Model" class="spec" rowspan="5" v-if="key%5==0" >{{(key / 5) +1}}</th>
              <th abbr="Model" class="spec" rowspan="5" v-if="key%5==0" >{{item[0]}}</th>
              <th abbr="Model" class="spec" rowspan="5" v-if="key%5==0" >{{item[1]}}</th>
              <td>{{item[2]}}</td>
              <td>{{item[3]}}</td>
              <td>{{item[4]}}</td>
              <td>{{item[5]}}</td>
              <td>{{item[6]}}</td>
              <td>{{item[7]}}</td>
              <td>{{item[8]}}</td>
              <td>{{item[9]}}</td>
              <td>{{item[10]}}</td>
              <td>{{item[11]}}</td>
              <td>{{item[12]}}</td>
            </tr>
          </table>
        </div>

        <div class="order-title" v-if="searchdata!='1'">
          <h2>医疗卫生机构</h2>
        </div>
        <div class="order-range" v-if="searchdata!='1'">
          <table id="mytable" cellspacing="0">
            <caption v-for="(detitem, detkey) in hospitaldetail" :key="detkey">
            <tr rowspan="2"><th scope="col" colspan="17">{{ detkey }}</th></tr>
            <tr>
              <th scope="col" style="width:50px;" rowspan="2">序号</th>
              <th scope="col" style="width:70px;" rowspan="2">组别</th>
              <th scope="col" rowspan="2">医疗机构名称</th>
              <th scope="col" rowspan="2">基准分</th>
              <th scope="col" rowspan="2">1.各入口是否有明显禁烟提示</th>
              <th scope="col" rowspan="2">2.控烟宣传阵地</th>
              <th scope="col" rowspan="2">3.是否全面禁烟或设置室外吸烟区</th>
              <th scope="col" rowspan="2">4.是否有控烟督导员</th>
              <th scope="col" colspan="5">5.室内场所情况</th>
              <th scope="col" rowspan="2">6.是否出售烟草制品</th>
              <th scope="col" rowspan="2">7.是否有烟草广告、促销或赞助</th>
              <th scope="col" rowspan="2">小计</th>
              <th scope="col" rowspan="2">备注</th>
            </tr>
            <tr>
              <th scope="col">(1)禁烟标识</th>
              <th scope="col">(2)有烟蒂</th>
              <th scope="col">(3)有烟具</th>
              <th scope="col">(4)有烟味</th>
              <th scope="col">(5)有人吸烟</th>
              <!--<th scope="col">(6)督导员劝阻</th>-->
            </tr>
            <tr v-for="(item, key) in detitem" :key="key">
              <th abbr="Model" class="spec">{{key+1}}</th>
              <th abbr="Model" class="spec">{{item.groupname}}</th>
              <th abbr="Model" class="spec">{{item.unitname}}</th>
              <td>64</td>
              <td>{{item.answer[0]}}</td>
              <td>{{item.answer[1]}}</td>
              <td>{{item.answer[2]}}</td>
              <td>{{item.answer[3]}}</td>
              <td>{{item.answer[4]}}</td>
              <td>{{item.answer[5]}}</td>
              <td>{{item.answer[6]}}</td>
              <td>{{item.answer[7]}}</td>
              <td>{{item.answer[8]}}</td>
              <td>{{item.answer[9]}}</td>
              <td>{{item.answer[10]}}</td>
              <!--<td>{{item.answer[11]}}</td>-->
              <td>{{item.total}}</td>
              <td>{{item.remark}}</td>
            </tr>
            <tr></tr>
            </caption>
          </table>
        </div>

        <div class="order-title" v-if="searchdata!='1'">
          <h2>医疗卫生机构场所明细</h2>
        </div>
        <div class="order-range" v-if="searchdata!='1'">
          <table id="mytabledetail" cellspacing="0">
            <caption v-for="(detitem, detkey) in hospitalplacedetail" :key="detkey">
            <tr rowspan="2"><th scope="col" colspan="17">{{ detkey }}</th></tr>
            <tr>
              <th scope="col" style="width:50px;">序号</th>
              <th scope="col" style="width:70px;">组别</th>
              <th scope="col">医疗机构名称</th>
              <th scope="col">控烟项目</th>
              <th scope="col">1.门卫室</th>
              <th scope="col">2.门急诊大厅</th>
              <th scope="col">3.手术室等候区</th>
              <th scope="col">4.ICU等候区</th>
              <th scope="col">5.电梯</th>
              <th scope="col">6.楼梯</th>
              <th scope="col">7.走廊</th>
              <th scope="col">8.厕所</th>
              <th scope="col">9.病区</th>
              <th scope="col">10.医生办公室</th>
              <th scope="col">11.会议室</th>
              <th scope="col">12.行政办公室</th>
              <th scope="col">13.其他</th>
            </tr>
            <tr v-for="(item, key) in detitem" :key="key">
              <th abbr="Model" class="spec" rowspan="5" v-if="key%5==0" >{{(key / 5) +1}}</th>
              <th abbr="Model" class="spec" rowspan="5" v-if="key%5==0" >{{item[0]}}</th>
              <th abbr="Model" class="spec" rowspan="5" v-if="key%5==0" >{{item[1]}}</th>
              <td>{{item[2]}}</td>
              <td>{{item[3]}}</td>
              <td>{{item[4]}}</td>
              <td>{{item[5]}}</td>
              <td>{{item[6]}}</td>
              <td>{{item[7]}}</td>
              <td>{{item[8]}}</td>
              <td>{{item[9]}}</td>
              <td>{{item[10]}}</td>
              <td>{{item[11]}}</td>
              <td>{{item[12]}}</td>
              <td>{{item[13]}}</td>
              <td>{{item[14]}}</td>
              <td>{{item[15]}}</td>
            </tr>
            <tr></tr>
            </caption>
          </table>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import XLSX from 'xlsx'
import XLSXStyle from 'xlsx-style'
import VolHeader from '@/components/basic/VolHeader.vue'
/* eslint-disable eqeqeq */
export default {
  components: { VolHeader },
  created () {},
  data () {
    return {
      searchOptions: {
        title: '机构类型',
        data: [
          { key: '1', value: '党政机关' },
          { key: '2', value: '医疗卫生机构' }
        ]
      },
      searchdata: '0',
      officedetails: [],
      hospitaldetail: {},
      officeplacedetails: [],
      hospitalplacedetail: {},
      url: 'api/v_questionnaireresult/GetQuestionnairesListWithType' // 后从加载数据的url
    }
  },
  mounted: function () {
    this.$nextTick(function () {
      // 调用需要执行的方法
      this.load()
    })
  },
  methods: {
    load () {
      this.officedetails = []
      this.hospitaldetail = {}
      this.officeplacedetails = []
      this.hospitalplacedetail = {}
      var param = { type: this.searchdata }
      this.http.post(this.url, param, '正在查询调查记录').then((data) => {
        this.updateTable(data)
      })
    },
    updateTable (data) {
      var txt = ''
      console.log(data)
      data.forEach(element => {
        if (element.typeid == '1') {
          var content = JSON.parse(element.answerscontent)
          var item = {
            'groupname': element.groupname,
            'unitname': element.unitname,
            'total': content.total,
            'answer': [],
            'remark': element.modifier
          }

          txt = (content.answers[0].checked == -1) ? '/' : (content.answers[0].checked == 1 ? 5 : 0)
          if (content.answers[0].remark + '' != '') {
            txt += '(' + content.answers[0].remark + ')'
          }
          item['answer'].push(txt)

          var pnt = this.get2ndResult(content.answers[1])
          item['answer'] = item['answer'].concat(pnt)

          switch (content.answers[2].checked) {
            case -1:
              txt = '/'
              break
            case 0:
              txt = 5
              break
            case 1:
              txt = this.getAbc(content.answers[2])
              break
            default:
              txt = 0
          }
          // txt = (content.answers[2].checked == -1) ? '/' : this.getAbc(content.answers[2])
          /* if (content.answers[2].remark + '' != '') {
            txt += '(' + content.answers[2].remark + ')'
          } */
          item['answer'].push(txt)

          txt = (content.answers[3].checked == -1) ? '/' : (content.answers[3].checked == 1 ? 3 : 0)
          if (content.answers[3].remark + '' != '') {
            txt += '(' + content.answers[3].remark + ')'
          }
          item['answer'].push(txt)

          // txt = (content.answers[4].checked == -1) ? '/' : (content.answers[4].checked >= 1 ? content.answers[4].checked + 1 : 0)
          var chk = content.answers[4].checked
          if (chk.length == 0 || chk[0] == '0') {
            txt = 0
          } else {
            if (chk.length >= 3) {
              txt = 4
            } else {
              txt = chk.length + 1
            }
          }
          if (content.answers[4].remark + '' != '') {
            txt += '(' + content.answers[4].remark + ')'
          }
          item['answer'].push(txt)

          txt = (content.answers[5].checked == -1) ? '/' : (content.answers[5].checked == 1 ? 0 : 4)
          if (content.answers[5].remark + '' != '') {
            txt += '(' + content.answers[5].remark + ')'
          }
          item['answer'].push(txt)

          txt = (content.answers[6].checked == -1) ? '/' : (content.answers[6].checked == 1 ? 0 : 4)
          if (content.answers[6].remark + '' != '') {
            txt += '(' + content.answers[6].remark + ')'
          }
          item['answer'].push(txt)

          this.officedetails.push(item)
          this.officeplacedetails = this.officeplacedetails.concat(this.getOffPlaDetails(content.answers[1], item))
        } else {
          var json = JSON.parse(element.answerscontent)
          var nditem = {
            'groupname': element.groupname,
            'unitname': element.unitname,
            'total': json.total,
            'answer': [],
            'details': [],
            'remark': element.modifier
          }

          txt = (json.answers[0].checked == -1) ? '/' : (json.answers[0].checked == 1 ? 5 : 0)
          if (json.answers[0].remark + '' != '') {
            txt += '(' + json.answers[0].remark + ')'
          }
          nditem['answer'].push(txt)

          txt = (json.answers[1].checked == -1) ? '/' : (json.answers[1].checked == 1 ? 5 : 0)
          if (json.answers[1].remark + '' != '') {
            txt += '(' + json.answers[1].remark + ')'
          }
          nditem['answer'].push(txt)

          txt = (json.answers[2].checked == -1) ? '/' : this.getHosAbc(json.answers[2])
          /* if (json.answers[2].remark + '' != '') {
            txt += '(' + json.answers[2].remark + ')'
          } */
          nditem['answer'].push(txt)

          txt = (json.answers[3].checked == -1) ? '/' : (json.answers[3].checked == 1 ? (json.answers[3].ext.indexOf('a') >= 0 ? 5 : 3) : 0)
          if (json.answers[3].remark + '' != '') {
            txt += '(' + json.answers[3].remark + ')'
          }
          if (json.answers[3].ext.indexOf('b') >= 0) {
            txt += '(' + '未佩戴督导胸牌或袖章' + ')'
          }
          nditem['answer'].push(txt)

          var ndpnt = this.getFifthResult(json.answers[4])
          nditem['answer'] = nditem['answer'].concat(ndpnt)

          txt = (json.answers[5].checked == -1) ? '/' : (json.answers[5].checked == 1 ? 0 : 5)
          if (json.answers[5].remark + '' != '') {
            txt += '(' + json.answers[5].remark + ')'
          }
          nditem['answer'].push(txt)

          txt = (json.answers[6].checked == -1) ? '/' : (json.answers[6].checked == 1 ? 0 : 5)
          if (json.answers[6].remark + '' != '') {
            txt += '(' + json.answers[6].remark + ')'
          }
          nditem['answer'].push(txt)

          if (!(element.classify in this.hospitaldetail)) {
            this.hospitaldetail[element.classify] = []
            this.hospitalplacedetail[element.classify] = []
          }
          this.hospitaldetail[element.classify].push(nditem)
          this.hospitalplacedetail[element.classify] = this.hospitalplacedetail[element.classify].concat(this.getHosPlaDetails(json.answers[4], nditem))
        }
      })
    },
    get2ndResult (answer) {
      var curpnts = [0, 0, 0, 0, 0]
      var remarks = ['', '', '', '', '']
      var notdef = true
      answer.answers.forEach(element => {
        if (element.answers[0].checked != -1) {
          notdef &= false
        }
        if (element.answers[0].checked == 0) {
          curpnts[0] += 1
        }
        if (element.answers[0].remark + '' != '') {
          remarks[0] += element.answers[0].remark
        }
        if (element.answers[1].checked != -1) {
          notdef &= false
        }
        if (element.answers[1].checked == 1) {
          curpnts[1] += 1
        }
        if (element.answers[1].remark + '' != '') {
          remarks[1] += element.answers[1].remark
        }
        if (element.answers[2].checked != -1) {
          notdef &= false
        }
        if (element.answers[2].checked == 1 && element.answers[2].ext1) {
          curpnts[2] += element.answers[2].ext1
        }
        if (element.answers[2].remark + '' != '') {
          remarks[2] += element.answers[2].remark
        }
        if (element.answers[3].checked != -1) {
          notdef &= false
        }
        if (element.answers[3].checked == 1 && element.answers[3].ext) {
          curpnts[3] += element.answers[3].ext
        }
        if (element.answers[3].remark + '' != '') {
          remarks[3] += element.answers[3].remark
        }
        if (element.answers[4].checked != -1) {
          notdef &= false
        }
        if (element.answers[4].checked == 1 && element.answers[4].ext) {
          curpnts[4] += element.answers[4].ext
        }
        if (element.answers[4].remark + '' != '') {
          remarks[4] += element.answers[4].remark
        }
      })

      if (notdef) {
        return ['/', '/', '/', '/', '/']
      }

      var pnt = []
      var txt = ''
      if (curpnts[0] > 5) {
        txt += -10
      } else {
        txt += -curpnts[0] * 2
      }
      if (remarks[0] != '') {
        txt += '(' + remarks[0] + ')'
      }
      pnt.push(txt)

      txt = ''
      if (curpnts[1] > 0) {
        txt += -10
      } else {
        txt += 0
      }
      if (remarks[1] != '') {
        txt += '(' + remarks[1] + ')'
      }
      pnt.push(txt)

      txt = ''
      if (curpnts[2] > 4) {
        txt += -20
      } else {
        txt += (-curpnts[2] * 5)
      }
      if (remarks[2] != '') {
        txt += '(' + remarks[2] + ')'
      }
      pnt.push(txt)

      txt = ''
      if (curpnts[3] > 5) {
        txt += (-15)
      } else {
        txt += (-curpnts[3] * 3)
      }
      if (remarks[3] != '') {
        txt += '(' + remarks[3] + ')'
      }
      pnt.push(txt)

      txt = ''
      if (curpnts[4] > 5) {
        txt += (-20)
      } else {
        txt += (-curpnts[4] * 4)
      }
      if (remarks[4] != '') {
        txt += '(' + remarks[4] + ')'
      }
      pnt.push(txt)

      return pnt
    },
    getOffPlaDetails (answer, item) {
      var res = [[], [], [], [], []]
      var i = 0
      for (i = 0; i < 5; i++) {
        res[i].push(item.groupname)
      }
      for (i = 0; i < 5; i++) {
        res[i].push(item.unitname)
      }
      res[0].push('(1)禁烟标识')
      res[1].push('(2)烟味')
      res[2].push('(3)吸烟')
      res[3].push('(4)烟具')
      res[4].push('(5)烟头')

      var txt = ''
      answer.answers.forEach(element => {
        if (element.answers[0].checked == -1) {
          res[0].push('/')
        } else if (element.answers[0].checked == 1) {
          res[0].push('0')
        } else {
          txt = '-2'
          if (element.answers[0].remark + '' != '') {
            txt += '(' + element.answers[0].remark + ')'
          }
          res[0].push(txt)
        }

        if (element.answers[1].checked == -1) {
          res[1].push('/')
        } else if (element.answers[1].checked == 0) {
          res[1].push('0')
        } else {
          txt = '-10'
          if (element.answers[1].remark + '' != '') {
            txt += '(' + element.answers[1].remark + ')'
          }
          res[1].push(txt)
        }

        if (element.answers[2].checked == -1) {
          res[2].push('/')
        } else if (element.answers[2].checked == 0) {
          res[2].push('0')
        } else {
          txt = -5 * element.answers[2].ext1
          if (element.answers[2].remark + '' != '') {
            txt += '(' + element.answers[2].remark + ')'
          }
          if (element.answers[2].ext == 1) {
            txt += '(工作人员吸烟)'
          }
          res[2].push(txt)
        }

        if (element.answers[3].checked == -1) {
          res[3].push('/')
        } else if (element.answers[3].checked == 0) {
          res[3].push('0')
        } else {
          txt = -3 * element.answers[3].ext
          if (element.answers[3].remark + '' != '') {
            txt += '(' + element.answers[3].remark + ')'
          }
          res[3].push(txt)
        }

        if (element.answers[4].checked == -1) {
          res[4].push('/')
        } else if (element.answers[4].checked == 0) {
          res[4].push('0')
        } else {
          txt = -4 * element.answers[4].ext
          if (element.answers[4].remark + '' != '') {
            txt += '(' + element.answers[4].remark + ')'
          }
          res[4].push(txt)
        }
      })

      return res
    },
    getFifthResult (answer) {
      var curpnts = [0, 0, 0, 0, 0, 0, 0, 0, 0]
      var remarks = ['', '', '', '', '', '']
      var notdef = true
      answer.answers.forEach(element => {
        if (element.answers[0].checked != -1) {
          notdef &= false
        }
        if (element.answers[0].checked == 0) {
          curpnts[0] += 1
        }
        remarks[0] += element.answers[0].remark

        if (element.answers[1].checked != -1) {
          notdef &= false
        }
        if (element.answers[1].checked == 1 && element.answers[1].ext > 0) {
          curpnts[1] += element.answers[1].ext
        }
        remarks[1] += element.answers[1].remark

        if (element.answers[2].checked != -1) {
          notdef &= false
        }
        if (element.answers[2].checked == 1 && element.answers[2].ext) {
          curpnts[2] += element.answers[2].ext
        }
        if (element.answers[2].remark + '' != '' && element.answers[2].remark != 1 && element.answers[2].remark != 0) {
          remarks[2] += element.answers[2].remark
        }

        if (element.answers[3].checked != -1) {
          notdef &= false
        }
        if (element.answers[3].checked == 1) {
          curpnts[3] += 1
        }
        remarks[3] += element.answers[3].remark

        if (element.answers[4].checked != -1) {
          notdef &= false
        }
        if (element.answers[4].checked == 1 && element.answers[4].ext) {
          curpnts[4] += element.answers[4].ext[0]
          curpnts[5] += element.answers[4].ext[1]
          curpnts[6] += element.answers[4].ext[2]
        }
        remarks[4] += element.answers[4].remark

        if (element.answers[4].checked == 1) {
          if (element.answers[5].checked != -1) {
            notdef &= false
          }
          if (element.answers[5].checked == 1) {
            curpnts[7] += 1
            remarks[5] += '(工作人员进行劝阻)'
          } else if (element.answers[5].checked == 0) {
            curpnts[8] += 1
            remarks[5] += '(无工作人员劝阻)'
          }
          // remarks[5] += element.answers[5].remark
        }
      })

      if (notdef) {
        return ['/', '/', '/', '/', '/'] //, '/']
      }

      var pnt = []
      var txt = ''
      if (curpnts[0] > 10) {
        txt += (-10)
      } else {
        txt += (-curpnts[0])
      }
      if (remarks[0] != '') {
        txt += '(' + remarks[0] + ')'
      }
      pnt.push(txt)

      txt = ''
      if (curpnts[1] > 5) {
        txt += (-10)
      } else {
        txt += (-curpnts[1] * 2)
      }
      if (remarks[1] != '') {
        txt += '(' + remarks[1] + ')'
      }
      pnt.push(txt)

      txt = ''
      if (curpnts[2] > 2) {
        txt += (-10)
      } else {
        txt += (-curpnts[2] * 5)
      }
      if (remarks[2] != '') {
        txt += '(' + remarks[2] + ')'
      }
      pnt.push(txt)

      txt = ''
      if (curpnts[3] > 0) {
        txt += (-9)
      } else {
        txt += (0)
      }
      if (remarks[3] != '') {
        txt += '(' + remarks[3] + ')'
      }
      pnt.push(txt)

      txt = ''
      var pt = 0
      if (curpnts[4] > 2) {
        pt -= 6
      } else {
        pt -= curpnts[4] * 3
      }

      if (curpnts[5] > 2) {
        pt -= 10
      } else {
        pt -= curpnts[5] * 5
      }

      if (curpnts[6] > 0) {
        pt -= 9
      }
      if (curpnts[8] == 0 && curpnts[7] >= 0) {
        // txt += '+5'
        pt += 5
      }
      txt += pt
      /* if (remarks[4] != '') {
        txt += '(' + remarks[4] + ')'
      } */
      /* pnt.push(txt)

      txt = ''
      if (curpnts[7] > 0) {
        txt += (5)
      } else {
        txt += (0)
      }
      if (remarks[5] != '') {
        txt += '(' + remarks[5] + ')'
      }
      pnt.push(txt) */

      /* if (remarks[5] != '') {
        txt += '(' + remarks[5] + ')'
      } */
      pnt.push(txt)

      return pnt
    },
    getHosPlaDetails (answer, item) {
      var res = [[], [], [], [], []] //, []]
      var i = 0
      for (i = 0; i < 5; i++) {
        res[i].push(item.groupname)
      }
      for (i = 0; i < 5; i++) {
        res[i].push(item.unitname)
      }
      res[0].push('(1)禁烟标识')
      res[1].push('(2)烟蒂')
      res[2].push('(3)烟具')
      res[3].push('(4)烟味')
      res[4].push('(5)吸烟')
      // res[5].push('(6)督导员劝阻')
      var txt = ''
      answer.answers.forEach(element => {
        if (element.answers[0].checked == -1) {
          res[0].push('/')
        } else if (element.answers[0].checked == 1) {
          res[0].push('0')
        } else {
          txt = '-1'
          if (element.answers[0].remark + '' != '') {
            txt += '(' + element.answers[0].remark + ')'
          }
          res[0].push(txt)
        }

        if (element.answers[1].checked == -1) {
          res[1].push('/')
        } else if (element.answers[1].checked == 0) {
          res[1].push('0')
        } else {
          txt = -2 * element.answers[1].ext
          if (element.answers[1].remark + '' != '') {
            txt += '(' + element.answers[1].remark + ')'
          }
          res[1].push(txt)
        }

        if (element.answers[2].checked == -1) {
          res[2].push('/')
        } else if (element.answers[2].checked == 0) {
          res[2].push('0')
        } else {
          txt = -5 * element.answers[2].ext
          if (element.answers[2].remark + '' != '') {
            txt += '(' + element.answers[2].remark + ')'
          }
          res[2].push(txt)
        }

        if (element.answers[3].checked == -1) {
          res[3].push('/')
        } else if (element.answers[3].checked == 0) {
          res[3].push('0')
        } else {
          txt = -9
          if (element.answers[3].remark + '' != '') {
            txt += '(' + element.answers[3].remark + ')'
          }
          res[3].push(txt)
        }

        if (element.answers[4].checked == -1) {
          res[4].push('/')
        } else if (element.answers[4].checked == 0) {
          res[4].push('0')
        } else {
          txt = ''
          var rr = 0
          if (element.answers[4].ext[0] > 0) {
            txt += -3 * element.answers[4].ext[0]
            rr += -3 * element.answers[4].ext[0]
            txt += '(外来人员吸烟)'
          }
          if (element.answers[4].ext[1] > 0) {
            txt += -5 * element.answers[4].ext[1]
            rr += -5 * element.answers[4].ext[1]
            txt += '(工作人员吸烟)'
          }
          if (element.answers[4].ext[2] > 0) {
            txt += -9
            rr += -9
            txt += '(行政领导吸烟)'
          }
          if (element.answers[4].remark + '' != '') {
            txt += '(' + element.answers[4].remark + ')'
          }
          // res[4].push(txt)

          if (element.answers[5].checked == 1) {
            rr += 5
            txt += '+5(工作人员劝阻)'
          } else if (element.answers[5].cheked == 0) {
            txt += '+0(无工作人员劝阻)'
          }
          res[4].push(rr) // + '(' + txt + ')')
        }

        /* if (element.answers[5].checked == -1) {
          res[5].push('/')
        } else if (element.answers[5].checked == 0) {
          txt = 0
          if (element.answers[5].remark + '' != '') {
            txt += '(' + element.answers[5].remark + ')'
          }
          res[4].push(txt)
        } else {
          txt = 5
          res[5].push(txt)
        } */
      })

      return res
    },
    getAbc (answer) {
      var res = 0
      if (answer.checked == 1) {
        if (answer.remark.indexOf('a') >= 0) {
          res += 2
        }
        if (answer.remark.indexOf('b') >= 0) {
          res += 2
        }
        if (answer.remark.indexOf('c') >= 0) {
          res += 1
        }
      }
      return res
    },
    getHosAbc (answer) {
      var res = 0
      if (answer.checked == 1) {
        if (answer.remark.indexOf('a') >= 0) {
          res += 2
        }
        if (answer.remark.indexOf('b') >= 0) {
          res += 2
        }
        if (answer.remark.indexOf('c') >= 0) {
          res += 2
        }
      } else if (answer.checked == 0) {
        res = 6
      }
      return res
    },
    exp () {
      let table1 = document.getElementById('table')
      let worksheet1 = XLSX.utils.table_to_sheet(table1)
      let workbook = XLSX.utils.book_new()
      XLSX.utils.book_append_sheet(workbook, worksheet1, '机关')
      let table2 = document.getElementById('tabledetail')
      let worksheet2 = XLSX.utils.table_to_sheet(table2)
      XLSX.utils.book_append_sheet(workbook, worksheet2, '机关场所明细')
      let table3 = document.getElementById('mytable')
      let worksheet3 = XLSX.utils.table_to_sheet(table3)
      XLSX.utils.book_append_sheet(workbook, worksheet3, '医疗机构')
      let table4 = document.getElementById('mytabledetail')
      let worksheet4 = XLSX.utils.table_to_sheet(table4)
      XLSX.utils.book_append_sheet(workbook, worksheet4, '医疗机构场所明细')

      // 以上四行也可以直接一行搞定，如果不需要对表格数据进行修改的话
      // let workbook = XLSX.utils.table_to_book(document.getElementById('table'))
      // this.setExcelStyle(workbook['Sheets']['机关'], workbook['Sheets']['机关场所明细'], workbook['Sheets']['医疗机构'], workbook['Sheets']['医疗机构场所明细']) // 设置列宽 字号等
      // this.addRangeBorder(workbook['Sheets']['机关'], workbook['Sheets']['机关场所明细'], workbook['Sheets']['医疗机构'], workbook['Sheets']['医疗机构场所明细'])
      // let wbOut = XLSXStyle.write(workbook, {type: 'buffer'})

      try {
        XLSX.writeFile(workbook, 'kongyandiaocha.xlsx')
      } catch (e) {
        console.log(e, workbook)
      }
    },
    getRows () {
      let rows = this.$refs.table.getSelected()
      if (rows.length == 0) {
        return this.$message.error('请先选中行1')
      }
      let text = '当前选中的行数据：' + JSON.stringify(rows)

      this.$Message.info(text)
    },
    setExcelStyle (data) {
      let borderAll = { // 单元格外侧框线
        top: {
          style: 'thin'
        },
        bottom: {
          style: 'thin'
        },
        left: {
          style: 'thin'
        },
        right: {
          style: 'thin'
        }
      }
      data['!cols'] = []
      for (let key in data) {
        // console.log(key)
        if (data[key] instanceof Object) {
          data[key].s = {
            border: borderAll,
            alignment: {
              horizontal: 'center', // 水平居中对齐
              vertical: 'center'
            },
            font: {
              sz: 11
            },
            bold: true,
            numFmt: 0
          }
          data['!cols'].push({wpx: 115})
        }
      }
      return data
    },
    addRangeBorder (range, ws) {
      let cols = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
      range.forEach(item => {
        console.log(item)
        let style = {
          s: {
            border: {
              top: { style: 'thin' },
              left: { style: 'thin' },
              bottom: { style: 'thin' },
              right: { style: 'thin' }
            }
          }
        }
        // 处理合并行
        for (let i = item.s.c; i <= item.e.c; i++) {
          ws[`${cols[i]}${Number(item.e.r) + 1}`] = ws[`${cols[i]}${Number(item.e.r) + 1}`] || style
          // 处理合并列
          for (let k = item.s.r + 2; k <= item.e.r + 1; k++) {
            ws[cols[i] + k] = ws[cols[k] + item.e.r] || style
          }
        }
      })
      return ws
    }
  }
}
</script>

<style lang="less" scoped>
.jn-day-total {
  display: flex;
  padding: 15px;
  background: white;
  .date-text {
    line-height: 36px;
    padding: 0 15px;
  }
  .date {
    margin-right: 20px;
  }
  .btn {
    margin-left: 10px;
  }
}
.order-title {
  h2 {
    padding: 7px 15px;
    font-weight: 500;
    background: white;
    border-bottom: 1px dotted #d4d4d4;
  }
}

.order-range {
  padding: 0 15px;
  background: white;
  background: white;
  display: flex;
  // flex-direction: row-reverse;
}

.order-range .order-item {
  box-shadow: 0 3px 13px rgba(117, 114, 114, 0.47);
  flex: 1;
  border-radius: 6px;
  font-size: 14px;
  text-align: center;
  border: 1px solid #e6e6e6;
  margin: 7px;
}

.order-range .total {
  color: white;
  font-size: 50px;
  font-weight: bold;
  line-height: 100px;
  background: #55ce80;
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
}

.order-range .name {
  font-size: 20px;
  padding: 10px;
}

.order-range .date {
  padding: 1px 0 20px 0;
  color: #9e9e9e;
  font-size: 13px;
}
a {
  color: #c75f3e;
}
#mytable {
  width: 100%;
  padding: 0;
  margin: 0;
}
#mytabledetail {
  width: 100%;
  padding: 0;
  margin: 0;
}
caption {
  padding: 0 0 5px 0;
  width: 100%;
  font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
  text-align: right;
}
th {
  font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
  color: #4f6b72;
  border: 1px solid #c1dad7;
  /* border-bottom: 1px solid #c1dad7;
  border-top: 1px solid #c1dad7; */
  letter-spacing: 2px;
  text-transform: uppercase;
  text-align: center;
  padding: 6px 6px 6px 12px;
}
th.nobg {
  border-top: 0;
  border-left: 0;
  border-right: 1px solid #c1dad7;
  background: none;
}
td {
  border-right: 1px solid #c1dad7;
  border-bottom: 1px solid #c1dad7;
  background: #fff;
  text-align: center;
  font-size: 11px;
  padding: 6px 6px 6px 12px;
  color: #4f6b72;
}
td.alt {
  background: #f5fafa;
  color: #797268;
}
th.spec {
  border-left: 1px solid #c1dad7;
  border-top: 0;
  background: #fff;
  font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
}
th.specalt {
  border-left: 1px solid #c1dad7;
  border-top: 0;
  background: #f5fafa;
  font: bold 10px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
  color: #797268;
}
</style>
